﻿using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vant.CellTypes;
using Vant.Properties;
using Vant.WpfControls.EditorSettings;

namespace Vant.Commands
{
    public class ToastDesigner : CommandDesigner
    {
        public override EditorSetting GetEditorSetting(PropertyDescriptor property, IBuilderCommandContext builderContext)
        {
            if(property.Name == nameof(Toast.loadingType))
            {
                return new LoadingTypeEditorSetting();
            }
            return base.GetEditorSetting(property, builderContext);
        }
    }

    [Designer("Vant.Commands.ToastDesigner, Vant")]
    [Icon("pack://application:,,,/ElementUI;component/Resources/Images/Notification.png")]
    [OrderWeight((int)OrderWeight.Toast)]
    public class Toast : VantCommandBase
    {
        [FormulaProperty(AcceptsReturn = true)]
        [SRDisplayName(nameof(Resources.Toast_Message))]
        public object message { get; set; }

        [SRComboProperty(ValueList = "text|success|fail|loading|html", DisplayList =nameof(Resources.Toast_Type_DisplayList))]
        [SRDisplayName(nameof(Resources.Toast_Type))]
        public string type { get; set; } = "success";

        [ComboProperty(ValueList = "spinner|circular", DisplayList = "spinner|circular")]
        [SRDisplayName(nameof(Resources.Toast_LoadingType))]
        public string loadingType { get; set; } = "circular";

        [SRComboProperty(ValueList = "middle|top|bottom", DisplayList = nameof(Resources.Toast_Position_DisplayList))]
        [SRDisplayName(nameof(Resources.Toast_Position))]
        public string position { get; set; } = "middle";

        [SRDisplayName(nameof(Resources.Notify_Duration))]
        [SRIntProperty(AllowNull =true, Watermark =nameof(Resources.Notify_Duration_Watermark))]
        public int? duration { get; set; }

        [SRDisplayName(nameof(Resources.Icon))]
        [IconProperty(DefaultIconColor = "white")]
        public ImageValue icon { get; set; }

        [SRDisplayName(nameof(Resources.IconSize))]
        [IntProperty(Min = 1)]
        public int iconSize { get; set; } = 20;

        [SRDisplayName(nameof(Resources.Toast_ForbidClick))]
        public bool forbidClick { get; set; }

        [SRDisplayName(nameof(Resources.Toast_Overlay))]
        public bool overlay { get; set; }

        [SRDisplayName(nameof(Resources.Toast_CloseOnClickOverlay))]
        public bool closeOnClickOverlay { get; set; }

        [SRDisplayName(nameof(Resources.Toast_CloseOnClick))]
        public bool closeOnClick { get; set; }

        public override string ToString()
        {
            return Resources.Toast;
        }

        public override bool GetDesignerPropertyVisible(string propertyName, CommandScope commandScope)
        {
            if(propertyName == nameof(closeOnClickOverlay))
            {
                return overlay && !forbidClick;
            }
            if(propertyName == nameof(loadingType))
            {
                return type == "loading";
            }
            if (propertyName == nameof(icon))
            {
                return type != "loading";
            }
            if (propertyName == nameof(closeOnClick))
            {
                return !forbidClick;
            }

            return base.GetDesignerPropertyVisible(propertyName, commandScope);
        }

        public override void InitDefaultPropertyValues()
        {
            base.InitDefaultPropertyValues();
            this.message = Resources.Toast_Message_DefaultValue;
            this.duration = 2000;
        }
    }
}
